package com.scwatch.ext.repository;

import com.scwatch.common.orm.Limitable;
import com.scwatch.ext.domain.ScheduleJob;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;

import java.util.List;

public interface ScheduleJobDao extends Repository<ScheduleJob, Integer> {
    Page<ScheduleJob> findAll(Specification<ScheduleJob> spec,
                              Pageable pageable);

    List<ScheduleJob> findAll(Specification<ScheduleJob> spec,
                              Limitable limitable);

    ScheduleJob findOne(Integer id);

    ScheduleJob save(ScheduleJob bean);

    void delete(ScheduleJob bean);

    List<ScheduleJob> findByjobName(String jobName);


    @Modifying
    @Query("from ScheduleJob bean where bean.site.id = ?1 ")
    public List<ScheduleJob> findAllByState(Integer siteId);

    @Modifying
    @Query(value = "select bean from ScheduleJob bean where bean.jobName = ?1 and bean.jobGroup = ?2 ")
    List<ScheduleJob> finByNameAndGroup(String jobName, String jobGroup);

    @Modifying
    @Query(value = "select bean from ScheduleJob bean where bean.beanClass = ?1 and bean.methodName = ?2 ")
    List<ScheduleJob> finByClassAndMethod(String beanClass, String methodName);


    @Modifying
    @Query("from ScheduleJob bean")
    public List<ScheduleJob> findAllByState();

}
